package com.ruoyi.blog.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.easywenku.entity.PromotionEducation;
import com.ruoyi.easywenku.service.PromotionEducationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * baomingController
 *
 * @author ruoyi
 * @date 2021-07-07
 */
@Controller
@RequestMapping("/baoming")
public class AipPromotionEducationController extends BaseController
{
    private String prefix = "baoming";

    @Autowired
    private PromotionEducationService promotionEducationService;

    @GetMapping()
    public String education()
    {
        return  "redirect:/baoming/";
    }
    @GetMapping({"/","index"})
    public String education1()
    {
        return prefix + "/index";
    } @GetMapping({"/2","/2/",})
    public String education2()
    {
        return prefix + "/index2";
    }
    /**
     * 查询baoming列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PromotionEducation promotionEducation)
    {
        startPage();
        List<PromotionEducation> list = promotionEducationService.list(new QueryWrapper<>(promotionEducation));
        return getDataTable(list);
    }



    /**
     * 新增baoming
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/index";
    }

    /**
     * 新增保存baoming
     */
    @PostMapping("/add")
    public String addSave(Model model, PromotionEducation promotionEducation)
    {
        promotionEducation.setCreateTime(new Date());
       promotionEducationService.save(promotionEducation);
       model.addAttribute("msg","保存成功");
       return prefix + "/index";
    }

    /**
     * 修改baoming
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PromotionEducation promotionEducation = promotionEducationService.getById(id);
        mmap.put("promotionEducation", promotionEducation);
        return prefix + "/edit";
    }

    /**
     * 修改保存baoming
     */
    @PostMapping("/edit")
    public AjaxResult editSave(PromotionEducation promotionEducation)
    {
        return toAjax(promotionEducationService.updateById(promotionEducation));
    }

    /**
     * 删除baoming
     */
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(promotionEducationService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
